<?php
/**
 * Disputeo session class. For storing user data during their session.
 * 
 * @package disputeo
 * @version 1.0
 * @author jimmy.dixon
 */

class Disputeo_Session extends Zend_Session
{

    /**
     * @var $obj Zend_Session_Namespace
     */
    protected $_namespace;
    
    /**
     * @var $obj Disputeo_Session
     */
    protected static $_instance;

    /**
     * Singleton constructor. Creates session namespace.
     */
    protected function __construct()
    {
        self::start();
        $this->_namespace = new Zend_Session_Namespace('disputeo');

        if (!isset($this->_namespace->initialized)) {
            self::regenerateId();
            $this->_namespace->initialized = true;
        }
    }

    /**
     * Initialise session object if not already set.
     */
    public static function getSession()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    /**
     * Set persistant session timeout
     * @var boolean
     */
    public function persist($remember = false)
    {
        if ($remember) {
            parent::rememberMe(2629743.83);
        }
    }

    /**
     * Get a session var
     * @param string $name
     * @return mixed
     */
    public function __get($name)
    {
        return isset($this->_namespace->$name) ? $this->_namespace->$name : null;
    }

    /**
     * Set a session var (name=>value)
     * @param string $name
     * @param mixed $value 
     */
    public function __set($name, $value)
    {
        $this->_namespace->$name = $value;
    }
    
    /**
     * End session
     */
    public function clear()
    {
        self::destroy(false);
    }

}